package com.carlos.gateway.security.handler;

import cn.hutool.core.date.DateUtil;
import cn.hutool.jwt.JWT;
import cn.hutool.jwt.signers.JWTSignerUtil;
import com.carlos.gateway.config.JwtConfig;
import com.carlos.gateway.security.JsonAuthentication;
import com.carlos.gateway.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 李健成
 * @date 2021/10/15
 */

@Component
public class MyAuthenticationSuccessHandler {

//    @Autowired
//    private JwtConfig jwtConfig;
//
//    @Override
//    public void onAuthenticationSuccess(HttpServletRequest httpServletR equest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException {
//
//        String jwt = JWT.create()
//                .setExpiresAt(DateUtil.tomorrow())
//                .setPayload("username", authentication.getName())
//                .setSigner(JWTSignerUtil.none())
//                .sign();
//        httpServletResponse.setHeader(jwtConfig.getHeader(), jwt);
//
//        ResultVO<Object> result = new ResultVO<>().success();
//        JsonAuthentication.writeJson(httpServletRequest, httpServletResponse, result);
//
//    }

}
